﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZL.Web.Utility;
using ZL.Web.Utility.Cache;
using ZLWeb.WebApiEntityBase;
using ZLWeb.WebApiEntityBase.RedisEntity;
using ZLWeb.WebApiRepository.Base;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.ModelBase;

namespace ZLWeb.WebApiInfrastructure.Base
{
    public class GloabAccidCacheHandler: Respository<AccidModel>, IGloabAccidCacheHandler
    {
        public IEnumerable<AccstatModel> GetAccidModelItems()
        {
            IEnumerable<AccstatModel> items = this.GetList<AccstatModel>("select  t2.accsta, t1.caccid,t1.ctype,t1.ccardno,t2.acccellno from cfv4cstat t1 join  cfv4accstat t2 on t1.caccid=t2.accid");
            string str = this.GetList<string>(@"select cast(i.siid as varchar(100)) +i.siidtype + v.svname from xtselfver v cross join xtselfidentity i").FirstOrDefault();
            if (str != null)
            {
                foreach (var item in items)
                {
                    item.mikey = str;
                }
            }
            return items;
        }

        public IEnumerable<AccstatModel> GetAccidModelItem(string ccardno)
        {

            long caccid = this.GetList<long>("select caccid from cfv4cstat where ccardno=@ccardno", new { ccardno }).FirstOrDefault();
            IEnumerable<AccstatModel> items = this.GetList<AccstatModel>("select  t2.accsta, t1.caccid,t1.ctype,t1.ccardno,t2.acccellno from cfv4cstat t1 join  cfv4accstat t2 on t1.caccid=t2.accid and t1.caccid=@caccid", new { caccid });
            string str = this.GetList<string>(@"select cast(i.siid as varchar(100)) +i.siidtype + v.svname from xtselfver v cross join xtselfidentity i").FirstOrDefault();
            if (str != null)
            {
                foreach (var item in items)
                {
                    item.mikey = str;
                }
            }
            return items;
        }


        public void SetContext(ZilLion.Service.Core.DapperWrapper.IDbContext item)
        {
            this.SetDbContext(item);
        }

        //public int CheckConfigItems()
        //{
        //    int logsnv2 = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='xtwxappidjoininfo'").GetValueOrDefault();
        //    return logsnv2;
        //}
    }
}
